package team3;

/**A Goodness function that looks only at the number of tiles controlled by a
 * player.
 * <p>
 * This function treats all tiles as having the same importance, and returns the
 * ratio of a players tiles to all tiles on the board.
 */
public class BoardControlGoodness implements GoodnessFunction
{
    /**Calculates the unweighted board control goodness for the given board state.
     * @param state State to calculate goodness for
     * @param playerToMaximize Player we're trying to maximize for
     * @return A value from 0 to 1, 1 being better for the player
     */
    public double evaluateGoodness(BoardState state, AI.Player playerToMaximize)
    {
        AI.Player[][] board = state.getState();
        double blackCount=0;
        double whiteCount=0;
        for (int row = 0; row < 8; row++)
        {
            for (int col = 0; col < 8; col ++)
            {
                if (board[row][col] == AI.Player.BLACK)
                    blackCount++;
                else if (board[row][col] == AI.Player.WHITE)
                    whiteCount++;
            }
        }
        double totalCount = blackCount + whiteCount;
        if(playerToMaximize==AI.Player.BLACK)
            return blackCount/totalCount;
        return whiteCount/totalCount;
    }

    public String getName()
    {
        return "board control";
    }
}
